﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Dyan.PlatformSystem.Configuration;
using Dyan.PlatformSystem.Web;

namespace Dyan.PlatformSystem.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class PlatformSystemDbContextFactory : IDesignTimeDbContextFactory<PlatformSystemDbContext>
    {
        public PlatformSystemDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<PlatformSystemDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder(), addUserSecrets: true);

            PlatformSystemDbContextConfigurer.Configure(builder, configuration.GetConnectionString(PlatformSystemConsts.ConnectionStringName));

            return new PlatformSystemDbContext(builder.Options);
        }
    }
}